package com.ddtech.business.vrTask.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.ddtech.business.common.BaseService;
import com.ddtech.business.vrTask.entity.VrTask;
import com.ddtech.business.vrTask.mapper.VrTaskMapper;
import com.ddtech.business.vrTask.query.VrTaskQuery;
import com.ddtech.business.vrTask.service.VrTaskService;
import com.ddtech.business.vrTask.vo.VrTaskVO;
import com.ddtech.exception.BadRequestException;
import com.ddtech.utils.PageUtil;
import com.ddtech.utils.SecurityUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Map;

/**
 * @version v1.0
 * @ClassName:VrTaskServiceImpl description：
 * @author:wei_zhang(xiao)
 * @date: 2024-11-15 13:36
 */
@Service
public class VrTaskServiceImpl extends BaseService<VrTaskMapper, VrTask>  implements VrTaskService {

    @Resource
    private VrTaskMapper vrTaskMapper;


    @Override
    public void create(VrTask vrTask) {
        vrTask.init();
        vrTask.setCreateUserName(SecurityUtils.getName());
        vrTask.setCreateUserId(SecurityUtils.getUserId());
        this.saveOrUpdate(vrTask);
    }

    @Override
    public void del(String id) {
        VrTaskVO vrTaskVO = vrTaskMapper.getTaskRoom(id);
        if(vrTaskVO.getRoomData()>0){
            throw new BadRequestException("任务已经创建房间，不能删除。");
        }
        this.removeById(id);
    }

    @Override
    public Object pageList(VrTaskQuery vrTaskQuery) {
        IPage<VrTask> page = this.page(vrTaskQuery.populatePage(), vrTaskQuery.autoWrapper());
        return PageUtil.toPage(page.getRecords(), page.getTotal());
    }

    @Override
    public Object list(VrTaskQuery vrTaskQuery) {
        return this.list(vrTaskQuery.autoWrapper());
    }

    @Override
    public Object taskWithRoom(VrTaskQuery vrTaskQuery) {
        IPage<Map<String, Object>> page = vrTaskMapper.getPageList(vrTaskQuery.populatePage(), vrTaskQuery);
        return PageUtil.toPage(page.getRecords(), page.getTotal());
    }
    @Override
    public Object taskWithRoomNoPage(VrTaskQuery vrTaskQuery) {
        return vrTaskMapper.getList(vrTaskQuery);
    }


}
